//
//  schoolListView.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/10/22.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "schoolListView.h"
#import "schoolModel.h"
@interface schoolListView() <UITableViewDelegate, UITableViewDataSource>
/** 学校数据*/
@property (nonatomic, strong) NSMutableArray *arrName;

@end
@implementation schoolListView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.arrName.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *const cellID = @"schoolCellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:13];
    cell.textLabel.text = self.arrName[indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(schoolListView:didSelectRowAtIndexPath:)]) {
        [self.delegate schoolListView:tableView didSelectRowAtIndexPath:indexPath];
    }
    [self removeFromSuperview];
}

- (IBAction)btnCclick:(id)sender {
    [self removeFromSuperview];
    
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}
- (NSMutableArray *)arrName{
    if(!_arrName){
        
        _arrName = [NSMutableArray array];
        
        
        for (int i = 0;i < self.modelArr.count; i++){
            schoolModel *model = self.modelArr[i];
            
            if (i==0) {
                [_arrName addObject:model.UNIVERSITY_NAME];
            }
            
            if (i>0) { // 从第二个数据开始判断返回的学校是不是一样的
                schoolModel *lastModel = self.modelArr[i-1];
                if (![model.UNIVERSITY_NAME isEqualToString:lastModel.UNIVERSITY_NAME]) { // 不是一样的就添加到arrName中
                    [_arrName addObject:model.UNIVERSITY_NAME];
                }
            }
            
        }
    }
    return _arrName;
}


@end

